﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace EA.Common
{
   public class StringUtil
    {


       public static Boolean IsPositiveNumber(String number)
       {
           String temp = "0123456789";
           int i;
           for (i = 0; i < number.Count(); i++)
           {
               int j;
               for (j = 0; j < temp.Count(); j++)
               {
                   if (temp[j] == number[i])
                   {
                       j = temp.Count();
                   }
               }

               if (j != temp.Count() + 1)
               {
                   i = number.Count();
               }
           }
           if (i == number.Count() + 1)
           {
               return false;
           }
           return true;
       }

       public static bool IsValidEmail(string email)
       {
           string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
 (com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";

           Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);

           bool valid = false;
           if (string.IsNullOrEmpty(email))
           {
               valid = false;
           }
           else
           {
               valid = check.IsMatch(email);
           }
           return valid;
       }

       public static String GetSQLDate()
       {
           DateTime date = DateTime.Now;
           return date.ToString("MM/dd/yyyy hh:mm");
       }

       public static Boolean IsNumeric(string stringToTest){
           decimal result; 
           return decimal.TryParse(stringToTest, out result);
       }


       public static int GetTimeSpan(DateTime value) { return DateTime.Now.Subtract(value).Milliseconds; }

    }

}
